export default class Block {
  constructor (row, col, d, item = 0, triggered = 0, sign = 0) {
    this.row = row
    this.col = col
    /*
      d = row * totalCols + col
    */
    this.d = d
    this.item = item
    /*
        0 = proto
        1 = triggered
    */
    this.triggered = triggered
    /*
      0 - nothing, click available
      1 - flag
      2 - question mark
      available only when triggered === 0
    */
    this.sign = sign
    this.userTrigger = false
  }

  swapItem(other) {
    [this.item, other.item] = [other.item, this.item]
  }

  userTriggered() {
    this.userTrigger = true
  }

  lClick() {
    if(this.triggered === 0){
      this.triggered = 1
    }
    return this.item
  }

  rClick() {
    const oldSign = this.sign
    this.sign = (this.sign + 1) % 3
    return [oldSign, this.sign, this.d]
  }

  isMine() {
    return this.item === -1
  }

  isTriggered() {
    return !!this.triggered
  }

  lAvail() {
    return !this.sign || !this.triggered
  }

  rAvail() {
    return !this.triggered
  }
}